import 'package:high_help_apps/common/entities/life_help/commodity_info_entity.dart';

commodityInfoEntityFromJson(CommodityInfoEntity data, Map<String, dynamic> json) {
	if (json['total'] != null) {
		data.total = json['total'] is String
				? int.tryParse(json['total'])
				: json['total'].toInt();
	}
	if (json['records'] != null) {
		data.records = (json['records'] as List).map((v) => CommodityInfoRecords().fromJson(v)).toList();
	}
	if (json['current'] != null) {
		data.current = json['current'] is String
				? int.tryParse(json['current'])
				: json['current'].toInt();
	}
	if (json['size'] != null) {
		data.size = json['size'] is String
				? int.tryParse(json['size'])
				: json['size'].toInt();
	}
	return data;
}

Map<String, dynamic> commodityInfoEntityToJson(CommodityInfoEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['total'] = entity.total;
	data['records'] =  entity.records.map((v) => v.toJson()).toList();
	data['current'] = entity.current;
	data['size'] = entity.size;
	return data;
}

commodityInfoRecordsFromJson(CommodityInfoRecords data, Map<String, dynamic> json) {
	if (json['create_at'] != null) {
		data.createAt = json['create_at'].toString();
	}
	if (json['update_at'] != null) {
		data.updateAt = json['update_at'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['user'] != null) {
		data.user = CommodityInfoRecordsUser().fromJson(json['user']);
	}
	if (json['title'] != null) {
		data.title = json['title'].toString();
	}
	if (json['original_price'] != null) {
		data.originalPrice = json['original_price'] is String
				? double.tryParse(json['original_price'])
				: json['original_price'].toDouble();
	}
	if (json['current_price'] != null) {
		data.currentPrice = json['current_price'] is String
				? double.tryParse(json['current_price'])
				: json['current_price'].toDouble();
	}
	if (json['desc'] != null) {
		data.desc = json['desc'].toString();
	}
	if (json['status'] != null) {
		data.status = json['status'] is String
				? int.tryParse(json['status'])
				: json['status'].toInt();
	}
	if (json['commodity_images'] != null) {
		data.commodityImages = (json['commodity_images'] as List).map((v) => CommodityInfoRecordsCommodityImages().fromJson(v)).toList();
	}
	if (json['is_selled'] != null) {
		data.isSelled = json['is_selled'] is String
				? int.tryParse(json['is_selled'])
				: json['is_selled'].toInt();
	}
	return data;
}

Map<String, dynamic> commodityInfoRecordsToJson(CommodityInfoRecords entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['create_at'] = entity.createAt;
	data['update_at'] = entity.updateAt;
	data['id'] = entity.id;
	data['user'] = entity.user.toJson();
	data['title'] = entity.title;
	data['original_price'] = entity.originalPrice;
	data['current_price'] = entity.currentPrice;
	data['desc'] = entity.desc;
	data['status'] = entity.status;
	data['commodity_images'] =  entity.commodityImages.map((v) => v.toJson()).toList();
	data['is_selled'] = entity.isSelled;
	return data;
}

commodityInfoRecordsUserFromJson(CommodityInfoRecordsUser data, Map<String, dynamic> json) {
	if (json['update_at'] != null) {
		data.updateAt = json['update_at'].toString();
	}
	if (json['uid'] != null) {
		data.uid = json['uid'] is String
				? int.tryParse(json['uid'])
				: json['uid'].toInt();
	}
	if (json['nick_name'] != null) {
		data.nickName = json['nick_name'].toString();
	}
	if (json['email'] != null) {
		data.email = json['email'].toString();
	}
	if (json['phone'] != null) {
		data.phone = json['phone'];
	}
	if (json['sex'] != null) {
		data.sex = json['sex'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['real_name'] != null) {
		data.realName = json['real_name'].toString();
	}
	if (json['create_at'] != null) {
		data.createAt = json['create_at'].toString();
	}
	if (json['role_int'] != null) {
		data.roleInt = json['role_int'];
	}
	if (json['avatar'] != null) {
		data.avatar = json['avatar'].toString();
	}
	if (json['birthday'] != null) {
		data.birthday = json['birthday'];
	}
	if (json['location'] != null) {
		data.location = json['location'];
	}
	return data;
}

Map<String, dynamic> commodityInfoRecordsUserToJson(CommodityInfoRecordsUser entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['update_at'] = entity.updateAt;
	data['uid'] = entity.uid;
	data['nick_name'] = entity.nickName;
	data['email'] = entity.email;
	data['phone'] = entity.phone;
	data['sex'] = entity.sex;
	data['id'] = entity.id;
	data['real_name'] = entity.realName;
	data['create_at'] = entity.createAt;
	data['role_int'] = entity.roleInt;
	data['avatar'] = entity.avatar;
	data['birthday'] = entity.birthday;
	data['location'] = entity.location;
	return data;
}

commodityInfoRecordsCommodityImagesFromJson(CommodityInfoRecordsCommodityImages data, Map<String, dynamic> json) {
	if (json['token'] != null) {
		data.token = json['token'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['create_at'] != null) {
		data.createAt = json['create_at'].toString();
	}
	if (json['update_at'] != null) {
		data.updateAt = json['update_at'].toString();
	}
	if (json['commodity_id'] != null) {
		data.commodityId = json['commodity_id'] is String
				? int.tryParse(json['commodity_id'])
				: json['commodity_id'].toInt();
	}
	return data;
}

Map<String, dynamic> commodityInfoRecordsCommodityImagesToJson(CommodityInfoRecordsCommodityImages entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['token'] = entity.token;
	data['id'] = entity.id;
	data['create_at'] = entity.createAt;
	data['update_at'] = entity.updateAt;
	data['commodity_id'] = entity.commodityId;
	return data;
}